//
//  MainWindowViewController.m
//  SpeedCoach Importer
//
//  Created by Roelant Ossewaarde on 4/8/11.
//  Copyright 2011 SUNY Buffalo. All rights reserved.
//

#import "MainWindowViewController.h"
#import <SpeedCoach_Importer_AppDelegate.h>


@implementation MainWindowViewController

@synthesize mainTextView;

-(void) awakeFromNib {
	[super awakeFromNib];
	SpeedCoach_Importer_AppDelegate	*appDelegate = (SpeedCoach_Importer_AppDelegate *)[NSApp delegate];
	[appDelegate setMwvc:self];
		
}

-(void) updateLogView {
	NSArray *logMessages = (NSArray *)[(SpeedCoach_Importer_AppDelegate *)[[NSApplication sharedApplication] delegate] logMessages];
	
	if ([self mainTextView] == nil) {
		NSLog(@"mainTextView is nil");
	} else {
		NSAttributedString *string = [self buildLogString:logMessages];
		NSTextStorage *nsts = [[self mainTextView] textStorage];
		[nsts setAttributedString:string];
	}
	
}


-(NSAttributedString *) buildLogString:(NSArray *) logMessages {
	NSString *theString = [[NSString alloc] initWithString:@"SpeedCoach Importer (version 1.1)\nAuthor: Roelant Ossewaarde\n\n"];
	for (LogMessage *msg in logMessages) {
		theString = [theString stringByAppendingFormat:@"%@ %i %@\n", [[msg timestamp] description], [msg severity], [msg message]];
	}
	return [[[NSAttributedString alloc] initWithString:theString] autorelease];
}

-(void) hideProgressIndicator {
	[progressIndicator stopAnimation:self];
	[progressIndicator setHidden:YES];
//	[progressLabel setStringValue:@"ked"];
}

-(void) showProgressIndicator {
	[progressIndicator setHidden:NO];
	[progressIndicator setMinValue:0];
	[progressIndicator setMaxValue:100];
	[progressIndicator setDoubleValue:0];
	[progressIndicator setIndeterminate:YES];
	[progressIndicator setUsesThreadedAnimation:YES];
	[progressIndicator startAnimation:self];
	[self setProgressLabelToString:@""];
	[progressLabel setHidden:NO];

}

-(void) updateProgressIndicatorWithDoubleValue:(double) value {
	[progressIndicator setIndeterminate:NO];
	[progressIndicator incrementBy:value];
}

-(void) updateProgressIndicatorToDoubleValue:(double) value {
	[progressIndicator setIndeterminate:NO];
	[progressIndicator setDoubleValue:value];
}

-(void) setProgressLabelToString:(NSString *)string {
	[progressLabel  setStringValue:string];
}
@end
